<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>BooleanModifier</title>
  <link rel="shortcut icon" type="image/x-icon" href="/examples/public/favicon.ico" >
  <link rel="stylesheet" href="../css/common.css">
</head>

<style>
  #app {
    width: 100%;
    height: 100%;
  }

</style>

<body>
  <div id="app"></div>
  <script type="module">
    import * as THREE from 'three'
    import * as Vis from '../../dist/Vis.es.js'
    const engine = new Vis.ModelingEngine()
    .setDom(document.getElementById('app'))
    .setSize()
    .setStats(true)
    .play()

    const scene = engine.scene

    const pointLight = new THREE.PointLight('rgb(255, 255, 255)', 1, 300, 0)
    pointLight.position.y = 30
    scene.add(pointLight)

    const box = new THREE.Mesh(
      new THREE.BoxBufferGeometry(20, 10, 10),
      new THREE.MeshStandardMaterial({ 
        // color: 'rgb(255, 105, 100)',
        map: new THREE.TextureLoader().load('/examples/public/texture/Bricks_Color.jpg')
      })
    )
    scene.add(box)

    const sphere = new THREE.Mesh(
      new THREE.SphereBufferGeometry(7),
      new THREE.MeshBasicMaterial({ 
        wireframe: true,
        color: 'rgb(155, 155, 0)',
        transparent: true,
        opacity: 0.5
      })
    )
    sphere.position.x = -5
    sphere.updateMatrix()
    scene.add(sphere)

    const cylinder = new THREE.Mesh(
      new THREE.CylinderGeometry(3, 3, 15, 16),
      sphere.material
    )
    cylinder.position.x = 5
    cylinder.updateMatrix()
    scene.add(cylinder)

    const modifier1 = new Vis.BooleanModifier({
      source: box,
      target: sphere
    })

    const modifier2 = new Vis.BooleanModifier({
      source: box,
      target: cylinder,
      mode: 'union'
    })

    engine.renderManager.addEventListener('render', () => {
      modifier1.render()
      modifier2.render()
    })

  </script>
  
</body>
</html>